package io.renren.modules.area.controller;

import java.util.Arrays;
import java.util.Map;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.renren.modules.area.entity.AreadetailEntity;
import io.renren.modules.poschangerecord.entity.PoschangerecordtableEntity;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.area.entity.AreaEntity;
import io.renren.modules.area.service.AreaService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-08-04 14:04:43
 */
@RestController
@RequestMapping("area/area")
public class AreaController {
    @Autowired
    private AreaService areaService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("area:area:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = areaService.queryPage(params);

        return R.ok().put("page", page);
    }

    @RequestMapping("/listAreaDetail")
    // @RequiresPermissions("poschangerecord:poschangerecordtable:list")
    public R listAreaDetail(@RequestParam Map<String, Object> params){
        // PageUtils page = poschangerecordtableService.queryPage(params);
        // 分页
        int pageIndex = Integer.parseInt(String.valueOf(params.get("page")));
        int pageSize = Integer.parseInt(String.valueOf(params.get("limit")));
        String areaId = String.valueOf(params.get("areaId"));
//        int areaId1 = -1;
//        if(areaId != null && !areaId.equals("")){
//            areaId1 = Integer.parseInt(areaId);
//        }
        Page<AreadetailEntity> page = new Page<>(pageIndex,pageSize);

        // 通过调用自定义dao层实现
        areaService.listAreaDetail(areaId,page);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{areaNo}")
    @RequiresPermissions("area:area:info")
    public R info(@PathVariable("areaNo") Integer areaNo){
		AreaEntity area = areaService.getById(areaNo);

        return R.ok().put("area", area);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("area:area:save")
    public R save(@RequestBody AreaEntity area){
		areaService.save(area);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("area:area:update")
    public R update(@RequestBody AreaEntity area){
		areaService.updateById(area);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("area:area:delete")
    public R delete(@RequestBody Integer[] areaNos){
		areaService.removeByIds(Arrays.asList(areaNos));

        return R.ok();
    }

}
